#include "RenderingSys/CameraUtitlity.h"

namespace GCRE {
	namespace Rendering {

		using namespace BasicType;

		void CameraUtitlity::Move( CCamera* pCamera, BasicType::SFVec3f direction, BasicType::SFFloat distance )
		{
			SFVec3f newViewpoint = pCamera->GetViewPoint() + direction * distance;
			pCamera->SetViewPoint( newViewpoint );
		}

		void CameraUtitlity::Rotate( CCamera* pCamera, BasicType::SFVec3f axis, BasicType::SFFloat rad )
		{
			SFMatrix44f m = MatrixUtitlity::RotationAxis( axis, rad );
			SFVec3f newAdvanceDirection = pCamera->GetAdvanceDirection();
			SFVec3f newUpDirection = pCamera->GetUpDirection();
			m.Transform( newAdvanceDirection, 0.0f );
			m.Transform( newUpDirection, 0.0f );
			pCamera->SetAdvanceDirection( newAdvanceDirection );
			pCamera->SetUpDirection( newUpDirection );
		}

		void CameraUtitlity::MoveForward( CCamera* pCamera, BasicType::SFFloat distance )
		{
			assert( distance > 0.0f );
			SFVec3f newViewpoint = pCamera->GetViewPoint() + pCamera->GetAdvanceDirection() * distance;
			pCamera->SetViewPoint( newViewpoint );
		}

		void CameraUtitlity::MoveBackward( CCamera* pCamera, BasicType::SFFloat distance )
		{
			assert( distance > 0.0f );
			SFVec3f newViewpoint = pCamera->GetViewPoint() - pCamera->GetAdvanceDirection() * distance;
			pCamera->SetViewPoint( newViewpoint );
		}

		void CameraUtitlity::MoveLeft( CCamera* pCamera, BasicType::SFFloat distance )
		{
			assert( distance > 0.0f );
		}

		void CameraUtitlity::MoveRight( CCamera* pCamera, BasicType::SFFloat distance )
		{
			assert( distance > 0.0f );
		}

		void CameraUtitlity::MoveUp( CCamera* pCamera, BasicType::SFFloat distance )
		{
			assert( distance > 0.0f );
			SFVec3f newViewpoint = pCamera->GetViewPoint() + pCamera->GetUpDirection() * distance;
			pCamera->SetViewPoint( newViewpoint );
		}

		void CameraUtitlity::MoveDown( CCamera* pCamera, BasicType::SFFloat distance )
		{
			assert( distance > 0.0f );
			SFVec3f newViewpoint = pCamera->GetViewPoint() - pCamera->GetUpDirection() * distance;
			pCamera->SetViewPoint( newViewpoint );
		}

		void CameraUtitlity::Roll( CCamera* pCamera, BasicType::SFFloat rad )
		{

		}

		void CameraUtitlity::Yaw( CCamera* pCamera, BasicType::SFFloat rad )
		{

		}

		void CameraUtitlity::Pitch( CCamera* pCamera, BasicType::SFFloat rad )
		{

		}

	}
}